package views;

import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.ui.part.ViewPart;


public class Options extends ViewPart {

	public static final String ID = "galileo.options";
	
	public Options() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
	      parent.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
	      
	      Label lblOPT = new Label(parent, SWT.NULL);
	      lblOPT.setText("Option");
	      lblOPT.setSize(15, 23);
	      lblOPT.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
	      
		//Language direction
		 Composite rdbGrpCont = new Composite(parent, SWT.NONE);
		 rdbGrpCont.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 rdbGrpCont.setLayout(new GridLayout());
		 
		 Label lblOpt1 = new Label(rdbGrpCont, SWT.NONE);
		 lblOpt1.setText("Language direction:");
		 lblOpt1.setBackground(Display.getCurrent().getSystemColor(
			SWT.COLOR_YELLOW));
		 
		 final Button rdbPl_ENG = new Button(rdbGrpCont, SWT.RADIO);
		 rdbPl_ENG.setText("pol-->eng");
		 rdbPl_ENG.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 final Button rdbENG_PL = new Button(rdbGrpCont, SWT.RADIO);
		 rdbENG_PL.setText("eng-->pl");
		 rdbENG_PL.setSelection(true);
		 rdbENG_PL.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 rdbPl_ENG.addSelectionListener(new SelectionAdapter() {
		    	public void widgetSelected(SelectionEvent e) {
		     		// Handle the selection event
		       		if(rdbPl_ENG.getSelection()) System.out.println("Checked pol-->eng!");
		       		else System.out.println("Checked eng-->pol!");		       		
		    	}
		 });
		 
		 //Learning preference
		 Composite rdbGrpCont2 = new Composite(parent, SWT.NONE);
		 rdbGrpCont2.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 rdbGrpCont2.setLayout(new GridLayout());
		 
		 Label lblOpt2 = new Label(rdbGrpCont2, SWT.NONE);
		 lblOpt2.setText("\n\n\nLearning preference:");
		 lblOpt2.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 final Button rdbALL = new Button(rdbGrpCont2, SWT.RADIO);
		 rdbALL.setText("All words in this level");
		 rdbALL.setSelection(true);
		 rdbALL.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 final Button rdbSPECIF = new Button(rdbGrpCont2, SWT.RADIO);
		 rdbSPECIF.setText("Specified number of words");
		 rdbSPECIF.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 final Combo cmbNum = new Combo(rdbGrpCont2, SWT.RIGHT);
		 inicializeCMBnum(cmbNum);
		 
		 rdbALL.addSelectionListener(new SelectionAdapter() {
		    	public void widgetSelected(SelectionEvent e) {
		     		// Handle the selection event
		       		if(rdbALL.getSelection()){
		       			System.out.println("All words in this level!");
		       			cmbNum.setEnabled(false);
		       		}
		       		else{
		       		     System.out.println("Specified number of words!");	
		       		     cmbNum.setEnabled(true);
		       		}
		    	}
		 });
		 
		 cmbNum.addSelectionListener(new SelectionAdapter() {
		    	public void widgetSelected(SelectionEvent e) {
		     		// Handle the selection event
		       		selectedCMB(cmbNum.getSelectionIndex());
		    	}
		 });
		 
		 //MODULE
		 Composite rdbGrpCont3 = new Composite(parent, SWT.NONE);
		 rdbGrpCont3.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 rdbGrpCont3.setLayout(new GridLayout());
		 
		 Label lblOpt3 = new Label(rdbGrpCont3, SWT.NONE);
		 lblOpt3.setText("\n\n\nModule:");
		 lblOpt3.setBackground(Display.getCurrent().getSystemColor(
			SWT.COLOR_YELLOW));
		 
		 final Button rdbTEST = new Button(rdbGrpCont3, SWT.RADIO);
		 rdbTEST.setText("Test");
		 rdbTEST.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 final Button rdbCOURSE = new Button(rdbGrpCont3, SWT.RADIO);
		 rdbCOURSE.setText("Course");
		 rdbCOURSE.setSelection(true);
		 rdbCOURSE.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 rdbTEST.addSelectionListener(new SelectionAdapter() {
		    	public void widgetSelected(SelectionEvent e) {
		     		// Handle the selection event
		       		if(rdbTEST.getSelection()) System.out.println("Checked TEST!");
		       		else System.out.println("Checked COURSE!");		       		
		    	}
		 });		 
		 
		 
		 //Action
		 Label lblTmp = new Label(parent, SWT.NONE);
		 lblTmp.setText("\n\n");
		 lblTmp.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 Composite rdbGrpCont4 = new Composite(parent, SWT.NONE);
		 GridLayout grid = new GridLayout();
		 grid.numColumns = 2;
		 grid.makeColumnsEqualWidth = true;
		 rdbGrpCont4.setLayout(grid);
		 rdbGrpCont4.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_YELLOW));
		 
		 final Button begin = new Button(rdbGrpCont4, SWT.NONE);
		 final Button finish = new Button(rdbGrpCont4, SWT.NONE);
		 
		 begin.setText("Begin");
		 finish.setText("Finish");
		 
		 begin.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_BLUE));
		 
		 finish.setBackground(Display.getCurrent().getSystemColor(
					SWT.COLOR_RED));
	    
		 begin.addSelectionListener(new SelectionAdapter() {
		   	public void widgetSelected(SelectionEvent e) {
		   		// Handle the selection event
		   		System.out.println("Begin!");
		   	}
		 });
		 
		 finish.addSelectionListener(new SelectionAdapter() {
		   	public void widgetSelected(SelectionEvent e) {
			   		// Handle the selection event
		   		System.out.println("Finish!");
		   	}
		 });
		 
		 //property 
	     GridLayoutFactory.fillDefaults().numColumns(1).spacing(5, 3).margins(5, 5).applyTo(parent);     
	}
	
	void inicializeCMBnum(Combo cmbNum){
		cmbNum.setEnabled(false);
		 cmbNum.add("5", 0);
		 cmbNum.add("10", 1);
		 cmbNum.add("15", 2);
		 cmbNum.add("20", 3);
		 cmbNum.add("25", 4);
		 cmbNum.add("30", 5);
		 cmbNum.add("All", 6);
	}
	
	void selectedCMB(int sel){
		switch(sel){
   		case 0:
   			System.out.println("Selected: 5!");
   			
   			break;
   		case 1:
   			System.out.println("Selected: 10!");
   			break;	
   		case 2:
   			System.out.println("Selected: 15!");
   			break;
   		case 4:
   			System.out.println("Selected: 20!");
   			break;
   		case 5:
   			System.out.println("Selected: 25!");
   			break;
   		case 6:
   			System.out.println("Selected: 30!");
   			break;
   		case 7:
   			System.out.println("Selected: All!");
   			break;
   		default:
   			System.out.println("Selected: BAD!");
   			break;
		}	
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
